﻿
using System;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Configuration;

namespace SalaryCom.Cool.Gadgets
{
    public class Seog_Jmt_XmlHelper
    {
        private readonly Seog_Jmt_Log objLog = new Seog_Jmt_Log();

        private string JobBoardDocsDirectoryFullPath => ConfigurationManager.AppSettings["JobBoardDocsDirectoryFullPath"];

        private string DocSalaryComDirectoryFullPath => ConfigurationManager.AppSettings["DocSalaryComDirectoryFullPath"];

        public string SalGetJobBoardDocFullXmlPath(string strRelativePath) => Path.Combine(JobBoardDocsDirectoryFullPath, strRelativePath);
       
        public string SalGetDocSalaryComFullXmlPath(string strRelativePath) => Path.Combine(DocSalaryComDirectoryFullPath, strRelativePath);
 
        public DataSet SalGetAllHotJobTitleFromXmlFile() => SalReadXml(SalGetJobBoardDocFullXmlPath(Seog_Jmt_Constant.AllHotJobTitleXmlFilePath));
        
     
        private DataSet SalReadXml(string strXmlFilePath)
        {            
            DataSet dstData = new DataSet();
            FileStream objFileStream = null;
            try
            {
                if (!File.Exists(strXmlFilePath))
                {
                    objLog.SalError("SalReadXml. Not find file:" + strXmlFilePath);
                    return dstData;
                }

                objFileStream = new FileStream(strXmlFilePath, System.IO.FileMode.Open, FileAccess.Read);
                dstData.ReadXml(objFileStream);
                return dstData;
            }
            catch (Exception ex)
            {
                objLog.SalError("SalReadXml. XmlFilePath=" + strXmlFilePath, ex);

                if (objFileStream != null)
                {
                    objFileStream.Close();
                    objFileStream.Dispose();
                    objFileStream = null;
                }
                return dstData;
            }
            finally
            {
                if (objFileStream != null)
                {
                    objFileStream.Close();
                    objFileStream.Dispose();
                    objFileStream = null;
                }
            }
        }

    }
}